home *** CD-ROM | disk | FTP | other *** search
/ Delphi Developer's Kit 1996 / Delphi Developer's Kit 1996.iso / power / wfc007.000 / src / drawobj.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-22  |  7.6 KB  |  398 lines

  1. #include <wfc.h>
  2. #pragma hdrstop
  3.  
  4. /*
  5. ** Author: Samuel R. Blackburn
  6. ** CI$: 76300,326
  7. ** Internet: sammy@sed.csc.com
  8. **
  9. ** You can use it any way you like.
  10. */
  11.  
  12. #if defined( _DEBUG )
  13. #undef THIS_FILE
  14. static char BASED_CODE THIS_FILE[] = __FILE__;
  15. #endif
  16.  
  17. /*
  18. ** A Rectangle drawing object
  19. */
  20.  
  21. IMPLEMENT_SERIAL( CRectangle, CObject, 1 )
  22.  
  23. CRectangle::CRectangle()
  24. {
  25.    m_Initialize();
  26. }
  27.  
  28. CRectangle::CRectangle( DWORD height, DWORD width, const CPoint& location, COLORREF fill_color, COLORREF line_color )
  29. {
  30.    m_Initialize();
  31.  
  32.    SetHeight( height );
  33.    SetWidth( width );
  34.    SetLocation( location );
  35.    SetFillColor( fill_color );
  36.    SetLineColor( line_color );
  37. }
  38.  
  39. CRectangle::~CRectangle()
  40. {
  41.    SetLocation( CPoint( 0, 0 ) );
  42. }
  43.  
  44. void CRectangle::Copy( const CRectangle& source )
  45. {
  46.    Copy( &source );
  47. }
  48.  
  49. void CRectangle::Copy( const CRectangle * source_p )
  50. {
  51.    m_Height        = source_p->m_Height;
  52.    m_Width         = source_p->m_Width;
  53.    m_LineColor     = source_p->m_LineColor;
  54.    m_FillColor     = source_p->m_FillColor;
  55.    m_Location      = source_p->m_Location;
  56.    m_LineRectangle = source_p->m_LineRectangle;
  57.    m_FillRectangle = source_p->m_FillRectangle;
  58. }
  59.  
  60. void CRectangle::Draw( CDC& device_context )
  61. {
  62.    device_context.FrameRect( m_LineRectangle, &CBrush( m_LineColor ) );
  63.    device_context.FillRect(  m_FillRectangle, &CBrush( m_FillColor ) );
  64. }
  65.  
  66. COLORREF CRectangle::GetFillColor( void ) const
  67. {
  68.    return( m_FillColor );
  69. }
  70.  
  71. DWORD CRectangle::GetHeight( void ) const
  72. {
  73.    return( m_Height );
  74. }
  75.  
  76. COLORREF CRectangle::GetLineColor( void ) const
  77. {
  78.    return( m_LineColor );
  79. }
  80.  
  81. void CRectangle::GetRectangle( CRect& destination ) const
  82. {
  83.    destination = m_LineRectangle;
  84. }
  85.  
  86. DWORD CRectangle::GetWidth( void ) const
  87. {
  88.    return( m_Width );
  89. }
  90.  
  91. void CRectangle::m_Initialize( void )
  92. {
  93.    m_Location.x = 0;
  94.    m_Location.y = 0;
  95.    m_LineRectangle.SetRectEmpty();
  96.    m_FillRectangle.SetRectEmpty();
  97.    SetFillColor( WHITE );
  98.    SetLineColor( BLACK );
  99. }
  100.  
  101. void CRectangle::m_SetRectangles( void )
  102. {
  103.    m_LineRectangle = CRect( m_Location.x, m_Location.y, m_Location.x + m_Width, m_Location.y + m_Height );
  104.    m_FillRectangle = m_LineRectangle;
  105.    m_FillRectangle.InflateRect( -1, -1 );
  106. }
  107.  
  108. void CRectangle::OnClick( void )
  109. {
  110.    return;
  111. }
  112.  
  113. void CRectangle::Serialize( CArchive& archive )
  114. {
  115.    CObject::Serialize( archive );
  116.  
  117.    if ( archive.IsStoring() )
  118.    {
  119.       archive << m_Height;
  120.       archive << m_Width;
  121.       archive << m_LineColor;
  122.       archive << m_FillColor;
  123.       archive << m_Location;
  124.    }
  125.    else
  126.    {
  127.       archive >> m_Height;
  128.       archive >> m_Width;
  129.       archive >> m_LineColor;
  130.       archive >> m_FillColor;
  131.       archive >> m_Location;
  132.  
  133.       SetHeight( m_Height );
  134.       SetWidth( m_Width );
  135.       SetLineColor( m_LineColor );
  136.       SetFillColor( m_FillColor );
  137.       SetLocation( m_Location );
  138.    }
  139. }
  140.  
  141. void CRectangle::SetFillColor( COLORREF color )
  142. {
  143.    m_FillColor = color;
  144. }
  145.  
  146. void CRectangle::SetHeight( DWORD height )
  147. {
  148.    m_Height = height;
  149.    m_SetRectangles();
  150. }
  151.  
  152. void CRectangle::SetLineColor( COLORREF color )
  153. {
  154.    m_LineColor = color;
  155. }
  156.  
  157. void CRectangle::SetLocation( const CPoint& source )
  158. {
  159.    m_Location = source;
  160.    m_SetRectangles();
  161. }
  162.  
  163. void CRectangle::SetSize( const CSize& size )
  164. {
  165.    SetWidth(  size.cx );
  166.    SetHeight( size.cy );
  167.    m_SetRectangles();
  168. }
  169.  
  170. void CRectangle::SetWidth( DWORD width )
  171. {
  172.    m_Width = width;
  173.    m_SetRectangles();
  174. }
  175.  
  176. /*
  177. ** Rounded Rectangle object
  178. */
  179.  
  180. IMPLEMENT_SERIAL( CRoundedRectangle, CRectangle, 1 )
  181.  
  182. CRoundedRectangle::CRoundedRectangle()
  183. {
  184. }
  185.  
  186. CRoundedRectangle::~CRoundedRectangle()
  187. {
  188. }
  189.  
  190. void CRoundedRectangle::Copy( const CRoundedRectangle& source )
  191. {
  192.    Copy( &source );
  193. }
  194.  
  195. void CRoundedRectangle::Copy( const CRoundedRectangle * source_p )
  196. {
  197.    CRectangle::Copy( source_p );
  198.  
  199.    m_RoundingPoint = source_p->m_RoundingPoint;
  200. }
  201.  
  202. void CRoundedRectangle::Draw( CDC& device_context )
  203. {
  204.    device_context.RoundRect( &m_LineRectangle, m_RoundingPoint );
  205. }
  206.  
  207. DWORD CRoundedRectangle::GetRoundingSize( void ) const
  208. {
  209.    return( m_RoundingPoint.x );
  210. }
  211.  
  212. void CRoundedRectangle::Serialize( CArchive& archive )
  213. {
  214.    CRectangle::Serialize( archive );
  215.  
  216.    if ( archive.IsStoring() )
  217.    {
  218.       archive << m_RoundingPoint.x;
  219.    }
  220.    else
  221.    {
  222.       archive >> m_RoundingPoint.x;
  223.  
  224.       SetRoundingSize( m_RoundingPoint.x );
  225.    }
  226. }
  227.  
  228. void CRoundedRectangle::SetRoundingSize( DWORD rounding_size )
  229. {
  230.    m_RoundingPoint.x = rounding_size;
  231.    m_RoundingPoint.y = rounding_size;
  232. }
  233.  
  234. /*
  235. ** A Square object
  236. */
  237.  
  238. IMPLEMENT_SERIAL( CSquare, CRectangle, 1 )
  239.  
  240. CSquare::CSquare()
  241. {
  242.    m_Initialize();
  243.  
  244.    SetHeight( 10 );
  245. }
  246.  
  247. CSquare::CSquare( DWORD size, const CPoint& location, COLORREF fill_color, COLORREF line_color )
  248. {
  249.    m_Initialize();
  250.  
  251.    SetHeight( size );
  252.    SetLocation( location );
  253.    SetFillColor( fill_color );
  254.    SetLineColor( line_color );
  255. }
  256.  
  257. CSquare::~CSquare()
  258. {
  259.    SetLocation( CPoint( 0, 0 ) );
  260. }
  261.  
  262. void CSquare::Serialize( CArchive& archive )
  263. {
  264.    CRectangle::Serialize( archive );
  265. }
  266.  
  267. void CSquare::SetHeight( DWORD height )
  268. {
  269.    m_Height = height;
  270.    m_Width  = height;
  271.    m_SetRectangles();
  272. }
  273.  
  274. void CSquare::SetSize( const CSize& size )
  275. {
  276.    m_Height = size.cx;
  277.    m_Width  = size.cx;
  278.    m_SetRectangles();
  279. }
  280.  
  281. void CSquare::SetWidth( DWORD width )
  282. {
  283.    m_Width  = width;
  284.    m_Height = width;
  285.    m_SetRectangles();
  286. }
  287.  
  288. /*
  289. ** An ellipse...
  290. */
  291.  
  292. IMPLEMENT_SERIAL( CEllipse, CRectangle, 1 )
  293.  
  294. CEllipse::CEllipse()
  295. {
  296.    m_Initialize();
  297. }
  298.  
  299. CEllipse::CEllipse( DWORD height, DWORD width, const CPoint& location, COLORREF fill_color, COLORREF line_color )
  300. {
  301.    m_Initialize();
  302.  
  303.    SetHeight( height );
  304.    SetWidth( width );
  305.    SetLocation( location );
  306.    SetFillColor( fill_color );
  307.    SetLineColor( line_color );
  308. }
  309.  
  310. CEllipse::~CEllipse()
  311. {
  312.    SetLocation( CPoint( 0, 0 ) );
  313. }
  314.  
  315. void CEllipse::Draw( CDC& device_context )
  316. {
  317.    CPen line_pen( PS_SOLID, 1, m_LineColor );
  318.  
  319.    CBrush fill_brush( m_FillColor );
  320.  
  321.    CPen   *old_pen   = device_context.SelectObject( &line_pen );
  322.    CBrush *old_brush = device_context.SelectObject( &fill_brush );
  323.  
  324.    device_context.Ellipse( m_LineRectangle );
  325.  
  326.    device_context.SelectObject( old_brush );
  327.    device_context.SelectObject( old_pen );
  328.  
  329.    fill_brush.DeleteObject();
  330.    line_pen.DeleteObject();
  331. }
  332.  
  333. void CEllipse::Serialize( CArchive& archive )
  334. {
  335.    CRectangle::Serialize( archive );
  336.  
  337.    if ( archive.IsStoring() != TRUE )
  338.    {
  339.       SetLineColor( m_LineColor );
  340.    }
  341. }
  342.  
  343. /*
  344. ** A Circle
  345. */
  346.  
  347. IMPLEMENT_SERIAL( CCircle, CSquare, 1 )
  348.  
  349. CCircle::CCircle()
  350. {
  351.    m_Initialize();
  352.  
  353.    SetHeight( 10 );
  354. }
  355.  
  356. CCircle::CCircle( DWORD size, const CPoint& location, COLORREF fill_color, COLORREF line_color )
  357. {
  358.    m_Initialize();
  359.  
  360.    SetHeight( size );
  361.    SetLocation( location );
  362.    SetFillColor( fill_color );
  363.    SetLineColor( line_color );
  364. }
  365.  
  366. CCircle::~CCircle()
  367. {
  368.    SetLocation( CPoint( 0, 0 ) );
  369. }
  370.  
  371. void CCircle::Draw( CDC& device_context )
  372. {
  373.    CPen line_pen( PS_SOLID, 1, m_LineColor );
  374.  
  375.    CBrush fill_brush( m_FillColor );
  376.  
  377.    CPen   *old_pen   = device_context.SelectObject( &line_pen );
  378.    CBrush *old_brush = device_context.SelectObject( &fill_brush );
  379.  
  380.    device_context.Ellipse( m_LineRectangle );
  381.  
  382.    device_context.SelectObject( old_brush );
  383.    device_context.SelectObject( old_pen );
  384.  
  385.    fill_brush.DeleteObject();
  386.    line_pen.DeleteObject();
  387. }
  388.  
  389. void CCircle::Serialize( CArchive& archive )
  390. {
  391.    CSquare::Serialize( archive );
  392.  
  393.    if ( archive.IsStoring() != TRUE )
  394.    {
  395.       SetLineColor( m_LineColor );
  396.    }
  397. }
  398.